{% extends 'admin/master.html' %}
{% import 'admin/lib.html' as lib with context %}
{% from 'admin/lib.html' import extra with context %} {# backward compatible #}

{% block head %}
  {{ super() }}
  {{ lib.form_css() }}
{% endblock %}

{% block body %}
  {% block navlinks %}
  <ul class="nav nav-tabs">
    <li>
        <a href="{{ url_for('.index') }}">95值计算</a>
    </li>
  </ul>
  {% endblock %}
<form id="search_frm" class="admin-form form-horizontal">
  <div class="form-group">
    <label for="exampleInputEmail1" class="col-md-2 control-label">机房选择</label>
  <div class="col-md-10">
      {% for item in idcs %}
          <label class="checkbox-inline">
          <input type="checkbox" name="chkidc_id" value="{{ item[0] }}"> {{ item[1] }}
        </label>
      {% endfor %}
  </div>
  </div>
  <div class="form-group">
    <label class="col-md-2 control-label">设备标识</label>
  <div class="col-md-10">
    {% for item in marks %}
          <label class="checkbox-inline">
          <input type="checkbox" name="machine_marks" value="{{ item[0] }}"> {{ '{}-{}'.format(item[0],item[1]) }}
        </label>
      {% endfor %}
  </div>
  </div>
<div class="form-group">
    <label for="deviceids" class="col-md-2 control-label">设备ID</label>
    <div class="col-md-10">
         <input class="form-control" id="deviceids" name="deviceids" placeholder="多个设备ID以逗号分隔" type="text" value="">
        </div>
  </div>
  <div class="form-group">
    <label for="inp_minuter" class="col-md-2 control-label">选择时间点</label>
      <div class="col-md-10">
    <input type="text" class="form-control" data-type="minute" name="inp_minuter" id="inp_minuter" readonly placeholder="时间取值方式，选择一个时间点，以该时间点为基准上下扩展2.5分钟即为取值时间点">
      <button type="button" id="search_btn" class="btn btn-default">搜索</button>
      </div>
  </div>
</form>
    <div>
    <div class="col-md-1"></div>
    <div class="col-md-11">
<div class="panel panel-default">
    <div class="panel-heading">参与计算的设备 <span id="will_calc_data_num"></span></div>
  <div class="panel-body">
    <ul id="will_calc_data">
</ul>
  </div>
</div>
<div class="panel panel-default">
    <div class="panel-heading">在该时间点找到数据的设备 <span id="find_machine_data_num"></span></div>
  <div class="panel-body">
    <ul id="find_machine_data">
</ul>
  </div>
</div>

<div class="panel panel-default">
    <div class="panel-heading">在该时间点未能找到数据的设备 <span id="cant_find_data_num"></span></div>
  <div class="panel-body">
    <ul id="cant_find_data">
</ul>
  </div>
</div>

 <div class="panel panel-default">
     <div class="panel-heading">在该时间点找到多个数据的设备 <span id="find_multi_data_num"></span></div>
  <div class="panel-body">
    <ul id="find_multi_data">
</ul>
  </div>
</div>
    <h3 id="bd95val"></h3>
</div>
    </div>


{% endblock %}

{% block tail %}
  {{ super() }}
  {{ lib.form_js() }}
<script src="/static/layer/layer.js?date=7.4.2"></script>
<script src="/static/laydate/laydate.js"></script>
    <script>
laydate.render({
    elem: '#inp_minuter',
    type: 'datetime',
});
$('#search_btn').click(function(){
      if($('#inp_minuter').val()==''){
          alert('时间点不能为空');
          return false;
      }
      var data = $("#search_frm").serialize();
      $('#bd95val').html('');
        $("#will_calc_data").find("li").remove();
        $("#find_machine_data").find("li").remove();
        $("#cant_find_data").find("li").remove();
        $("#find_multi_data").find("li").remove();
      $.ajax({
        type:'get',
        url:"{{ url_for('.search_result') }}",
        cache: false,
        data:data,  //重点必须为一个变量如：data
        dataType:'json',
        success:function(data){
            if(data.code==200){
                $('#bd95val').html(data.msg.bd95val);
                $("#will_calc_data").find("li").remove();
                $("#find_machine_data").find("li").remove();
                $("#cant_find_data").find("li").remove();
                $("#find_multi_data").find("li").remove();
                $('#will_calc_data_num').html(data.msg.will_calc_data.length)
                $('#find_machine_data_num').html(data.msg.find_machine_data.length)
                $('#cant_find_data_num').html(data.msg.cant_find_data.length)
                $('#find_multi_data_num').html(data.msg.find_multi_data.length)
                $.each(data.msg.will_calc_data,function(index,p){
                    $('#will_calc_data').append('<li class="item" >'+p[0]+','+p[1]+','+p[2]+'</li>');
                });
                $.each(data.msg.find_machine_data,function(index,p){
                    $('#find_machine_data').append('<li class="item" >'+p[0]+','+p[1]+','+p[2]+','+p[3]+'</li>');
                });
                $.each(data.msg.cant_find_data,function(index,p){
                    $('#cant_find_data').append('<li class="item" >'+p[0]+','+p[1]+','+p[2]+'</li>');
                });
                $.each(data.msg.find_multi_data,function(index,p){
                    $('#find_multi_data').append('<li class="item" >'+p[0]+','+p[1]+','+p[2]+','+p[3]+'</li>');
                });
                alert('数据已加载');
            }else {
                alert(data.msg);
            }
        },
        error:function(){
         alert("请求失败")
        }
       })
});

</script>
{% endblock %}
